/*
 * Project : PL/X Compiler
 * Date : 21/11/2011
 *	Author : Fu Jie
 * SID: 10072130141		
 * E-mail: fujie1988@gmail.com
 * Website: http://ajayjay.com
 */

#include<stdio.h>
#include<string.h>
#include<ctype.h>


#define TABLE
#define INSTRUCTION
#define SOURCE
#define ERROR


#define Number  22 //Number of reserved word
#define TXMAX  100 //MAX Symbol table length
#define InMax 200  //MAX instruction number
#define StMax 500	//MAX stack length
#define IMax  10 //MAX ident length
#define DMax  14 //MAX digit length
#define AddMax  2048 //MAX address

enum symbol {$,//stop symbol
	nul,	aident,	bident,	number,	plus,	minus,	times,	slash,	
	eql,	neq,	lss,	leq,	gtr,	geq,	lparen,	rparen,	comma,	semicolon,	
	period,	becomes,	progsym,	intesym,	logisym,	ifsym,	thensym,	
	elsesym,	whilesym,	repeasym,	beginsym,endsym, orsym, andsym,
	notsym, truesym, falsesym, dosym, untilsym, writesym , 
	/*******Extention Symbol********/
	forsym, tosym , dtosym, stepsym , pluseql, incre, mineql , decre , muleql , mod 
};

enum fct {		//instruction type
	lit,		opr,		lod,		sto,		Int,		jmp,		jpc
};

enum objekt {		//ident type
	integer,		logical
};

typedef struct instruction {
	fct f;
	int l;
	int a;
}Instruction;

typedef struct Table {	//Symbol table
	char name[IMax];
	objekt kind;
	int adr;
	int level;
	int size; /*m*/
}Table;


/************Functions************/
void init();
void Error(char* e);
void getch();
void getsym();
bool prog();
bool ds(int* pdx, int lev);
bool ss(int lev);
bool d(int* pdx, int lev);
bool s(int lev);
bool ae(int lev);
bool be(int lev);
bool at(int lev);
bool af(int lev);
bool bt(int lev);
bool bf(int lev);
bool re(int lev);
void interpret();
void listall();
bool noerror();
void closeFile();
FILE* openFile(char*);